package com.minishift.android.base;

import com.minishift.android.init.InitAction;
import com.minishift.android.utils.XActivitiyManager;
import com.minishift.android.utils.XExceptionHandler;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

/**
 * 
 * this class is base class.
 * if you want to use mini-shift, and you must make you Activity extends it.
 * @author Sirier
 *
 */
public abstract class XActivity extends Activity implements OnClickListener{
	
	public static final int TOAST_LONG = Toast.LENGTH_LONG;
	public static final int TOAST_SHORT = Toast.LENGTH_SHORT;
	public final Context context = this;
	
	/**
	 * this method will be executed before onCreate().
	 */
	protected void onCreateBefore() {

	}
	
	/***
	 * overriding the onCreate().
	 * it will initialize some configes.
	 * so, this method shouldn't be overrode.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		onCreateBefore();
		super.onCreate(savedInstanceState);
		InitAction.getInstance().init(this);
		XActivitiyManager.getXActivityManager().addActivity(this);
		XExceptionHandler.getExceptionHandler().init(this);
		onCreateAfter(savedInstanceState);
		init();
	}

	/**
	 * this method will be executed after onCreate().
	 */
	protected void onCreateAfter(Bundle savedInstanceState) {
		
	}

	/**
	 * if you have some objects, this method should be overrode.
	 * this method will initialize the object without widget.
	 */
	protected abstract void init();

	/**
	 * if you have some widgets, and this widgets have the onClicker.
	 * you must override this method and implement onClick.
	 */
	@Override
	public void onClick(View v) {
		
	}
	
	/**
	 * this method will be executed when this Activity is destroyed.
	 * and this Activity will complete finish.
	 */
	@Override
	protected void onDestroy() {
		super.onDestroy();
		XActivitiyManager.getXActivityManager().finishActivity(this);
	}
	
	/**
	 * if you want from current Activity to other Activity and no parameter.
	 * @param clazz: other Activity
	 * @param isFinish: true, current Activity will be finished.
	 */
	public void startActivity(Class<?> clazz, boolean isFinish) {
		startActivity(new Intent(this, clazz));			
		if(isFinish){
			finish();
		}else{
			
		}
	}
	
	/**
	 * this method will show a messageBox with text.
	 * @param String: will be showed message. 
	 */
	public void showShortMessage(String text){
		Toast.makeText(this, text, TOAST_SHORT).show();
	}
	
	/**
	 * this method will show a messageBox with text.
	 * @param String: will be showed message. 
	 */
	public void showLongMessage(String text){
		Toast.makeText(this, text, TOAST_LONG).show();
	}
	
	/**
	 * this method will show a messageBox with text.
	 * @param String: will be showed message. 
	 * @param int: times
	 */
	public void showMessage(String text, int times){
		Toast.makeText(this, text, times).show();
	}
	
}
